from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class SharePage:
    def __init__(self, driver):
        self.driver = driver
        self.share_button_locator = (By.ID, "share-button")
        self.facebook_share_locator = (By.ID, "facebook-share")
        self.twitter_share_locator = (By.ID, "twitter-share")
        self.email_share_locator = (By.ID, "email-share")
        self.share_modal_locator = (By.ID, "share-modal")
        self.close_share_modal_locator = (By.ID, "close-share-modal")
        self.success_message_locator = (By.ID, "success-message")
        self.error_message_locator = (By.ID, "error-message")

    def navigate(self):
        self.driver.get('http://example.com/share')

    def click_share_button(self):
        share_button = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(self.share_button_locator)
        )
        share_button.click()

    def click_facebook_share(self):
        facebook_share = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(self.facebook_share_locator)
        )
        facebook_share.click()

    def click_twitter_share(self):
        twitter_share = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(self.twitter_share_locator)
        )
        twitter_share.click()

    def click_email_share(self):
        email_share = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(self.email_share_locator)
        )
        email_share.click()

    def close_share_modal(self):
        close_share_modal = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable(self.close_share_modal_locator)
        )
        close_share_modal.click()

    def get_success_message(self):
        success_message = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(self.success_message_locator)
        )
        return success_message.text

    def get_error_message(self):
        error_message = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(self.error_message_locator)
        )
        return error_message.text

    def is_share_modal_open(self):
        share_modal = WebDriverWait(self.driver, 10).until(
            EC.visibility_of_element_located(self.share_modal_locator)
        )
        return share_modal.is_displayed()